//
//  LWTableViewController.m
//  LWCell展开和关闭
//
//  Created by huanglinwang on 16/11/5.
//  Copyright © 2016年 Linwang. All rights reserved.
//

#import "AXFUserInfoController.h"
#import "AXFUserInfoCell.h"

static NSString *cellID = @"CellID";

@interface AXFUserInfoController ()

@end

@implementation AXFUserInfoController{
    // 数据源
    NSArray<AXFDataModel *> *_dataList;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
    
    // 加载数据
    [self loadData];
    // 界面
    [self setupUI];
}

-(void)setupUI{
    
    self.tableView.estimatedRowHeight = 100;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"AXFUserInfoCell" bundle:nil] forCellReuseIdentifier:cellID];
    
    // 监测通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(lwReloadData:) name:@"switchButton" object:nil];
}
// 通知事件
-(void)lwReloadData:(NSNotification *)noti{
    
    AXFUserInfoCell *cell = [noti object];
    
    NSIndexPath *index = [self.tableView indexPathForCell:cell];
    NSLog(@"====>%@",index);
    [self.tableView reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationFade];
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _dataList.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    AXFUserInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    
    cell.model = _dataList[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}


#pragma mark - 加载数据
-(void)loadData{
    
    [_ModelMgr systemMessages:^(NSArray<AXFDataModel *> * _Nullable models) {
        _dataList = models;
        
//        [_dataList enumerateObjectsUsingBlock:^(AXFDataModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//            obj.lines = 1;
//        }];

        [self.tableView reloadData];
    }];
}

@end
